﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DatabaseAccess;
using System.Data;
using Liguo.AppCode;

namespace Liguo.Store
{
    public partial class Addaddress : System.Web.UI.Page
    {
        int choiceCo = 0;
        Int32 areaNun = 0;
        String condition = "ID between 1 and 4";
        string userId;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["User"] == null)
            {
                Response.Redirect("Port.aspx");
            }
            User user = (User)Session["User"];
            //获得UserID
            userId = user.UserID.ToString();
            if (!IsPostBack)
            {
                SqlIt sql = new SqlIt();
                DataSet ds = sql.SpecialItem("AddressInfo", condition);
                choiceBuilding.DataSource = ds.Tables[0].DefaultView;
                choiceBuilding.DataTextField = "Area";
                choiceBuilding.DataValueField = "ID";
                choiceBuilding.DataBind();
            }
        }

        protected void choiceCollege_SelectedIndexChanged(object sender, EventArgs e)
        {
            choiceCo = choiceCollege.SelectedIndex;
            switch (choiceCo)
            {
                case 0:
                    areaNun = 0;
                    condition = "ID between 1 and 4";
                    break;
                case 1:
                    areaNun = 128;
                    condition = "ID = 134";
                    break;
                case 2:
                    areaNun = 256;
                    condition = "ID between 263 and 265";
                    break;
                case 3:
                    areaNun = 384;
                    condition = "ID between 401 and 404";
                    break;
                case 4:
                    areaNun = 512;
                    condition = "ID between 560 and 561";
                    break;
                case 5:
                    areaNun = 640;
                    condition = "ID between 690 and 692";
                    break;
            }
            SqlIt sql = new SqlIt();
            DataSet ds = sql.SpecialItem("AddressInfo", condition);
            choiceBuilding.DataSource = ds.Tables[0].DefaultView;
            choiceBuilding.DataTextField = "Area";
            choiceBuilding.DataValueField = "ID";
            choiceBuilding.DataBind();

        }

        protected void saveChange_Click(object sender, EventArgs e)
        {
            string name = c_name.Text.ToString();
            string phone = c_phoneNum.Text.ToString();
            string areaID = choiceBuilding.SelectedValue.ToString();
            string detailAdd = detailAddress.Text.ToString();
            
            //string userId = "140";

            SqlIt sql = new SqlIt();
            Dictionary<string, string> dt = new Dictionary<string, string>();
            dt.Add("userID", userId);
            dt.Add("CustomerName", name);
            dt.Add("Address", areaID);
            dt.Add("DetailAddr", detailAdd);
            dt.Add("Tel", phone);

            sql.AddMess("DeliveryInfo", dt);
            Page.ClientScript.RegisterStartupScript(this.GetType(), "dialog", "<script>okkk();</script>");
            //Response.Write("<script>location.reload();</script>");
        }

        protected void cancel_Click(object sender, EventArgs e)
        {
            Page.ClientScript.RegisterStartupScript(this.GetType(), "dialog", "<script>okkk();</script>");
        }
    }
}
